// pages/product-list/product-list.js
import {feach} from '../../http/http'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderBy: 'default',
    categoryId: '',
    productList: []
  },
  onOrderByPrice(e) {
    // console.log('点击了筛选:', e);
    const orderBy = e.currentTarget.dataset.orderby
    // console.log( e.currentTarget.dataset);
    
    this.setData({
      orderBy: orderBy
    })
  },

    // 跳转到商品详情页
    selectProduct(e) {
      const {id} = e.currentTarget.dataset
      wx.navigateTo({
        url: '/pages/product-detail/product-detail' + "?id=" + id
      })
    },
    /*
    发送获取产品列表数据请求
    */ 
   getProductList() {
     const params = {
      categoryId: this.categoryId,
      orderBy: this.orderBy,
      pageNum: 1,
      pageSize:20
     }
    feach('/product/list', params ).then(res => {
      console.log(res);
      const {data} = res.data
      this.setData({
        productList: data.list
      })
    })
   },

    onLoad(query) {
      console.log('query:', query);
      this.categoryId = query.categoryId
      this.getProductList()
    }

 
})